package com.wangx1n.boobey.service;

import com.google.gson.Gson;
import com.wangx1n.boobey.dao.SuggestionMapper;
import com.wangx1n.boobey.dao.UserMapper;
import com.wangx1n.boobey.entity.Suggestion;
import com.wangx1n.boobey.entity.User;
import com.wangx1n.boobey.util.ApiResult;
import com.wangx1n.boobey.util.CodeMsg;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;

/**
 * @author wangxin
 * @create 2020-06-12 23:58
 */
@Service
public class SuggestionService {
    @Resource
    SuggestionMapper suggestionMapper;
    @Resource
    UserMapper userMapper;
    public String addSuggestion(Suggestion suggestion){
        Gson gson = new Gson();
            if(userMapper.selectByPrimaryKey(suggestion.getOpenid())==null){
                return gson.toJson(ApiResult.error(CodeMsg.NO_USER));
            }
        System.out.println(suggestion);
        suggestionMapper.insert(suggestion);
        return gson.toJson(ApiResult.success("成功",0));
    }
}
